package com.xzit.headline.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.google.gson.Gson;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public abstract class BaseFragment extends Fragment {
    protected View fragmentView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (fragmentView == null) {
            fragmentView = getMyView();
        } else {
            ViewGroup viewGroup = (ViewGroup) fragmentView.getParent();
            if (viewGroup != null) {
                viewGroup.removeView(fragmentView);
            }
        }
        return fragmentView;
    }

    public View getMyView() {
        EditText editText = new EditText(getActivity());
        editText.setBackgroundColor(Color.GREEN);
        editText.setText("P1");
        editText.setTextSize(22);
        editText.setGravity(Gravity.CENTER);
        return editText;
    }

    //地址
    public static String HOST = "http://192.168.1.100:8080/";
    public static String BASEURL = "http://192.168.1.100:8080/jrtt/";


    protected Retrofit retrofit;
    public BaseFragment() {
        retrofit = new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create(new Gson()))
                .build();

    }
}
